﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
namespace XLDL.Includes
{
    public partial class Comment : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["id"].ToString();
            xuat_comment(int.Parse( id));
        }

        protected void LinkButton_danhgia_Click(object sender, EventArgs e)
        {
            if (this.Panel_danhgia.Visible == false)
            {
                this.Panel_danhgia.Visible = true;
               this.Button_goi.Focus();

            }
            else
            {
                this.Panel_danhgia.Visible = false;
               this.Button_goi.Focus();
            }
        }
        protected void Button_goi_Click(object sender, EventArgs e)
        {
            string id = Request.QueryString["id"].ToString();
            DataTable tb = new DataTable();
            string lenh = "insert into Comment(id_sp,ten_nguoi_comment,noi_dung,ngay_comment) values(" + int.Parse(id) + ",N'" + TextBox_ten.Text + "',N'" + TextBox_noidung.Text + "','" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt") + "')";
            tb = new DataTable();
            tb = XLDL.XLDaTa(lenh);
            TextBox_noidung.Text = "";
            xuat_comment(int.Parse(id));
        }
        protected void xuat_comment(int id)
        {
            // lay comment

            DataTable tb = new DataTable();
            tb.Clear();
            tb = XLDL.XLDaTa("select * from comment where id_sp=" + id + " order by ngay_comment desc");

            this.LinkButton_danhgia.Text = "Đánh giá (" + tb.Rows.Count + ")";
            StringBuilder st = new StringBuilder();
            if (tb.Rows.Count == 0)
            {
                st.Append("<table border='0' width='405'>");
                st.Append("<tr><td align='left'><i>Chưa có đánh giá.</i></td></tr>");
                st.Append("<tr><td align='left'>&nbsp;</td></tr>");
                st.Append("</table>");
            }
            else
            {
                //string s = "9999999999999999999999999999999999999999999999999999999999999999999999999999";
               st.Append("<span style='width: 406px'>");
                st.Append("<table border='0' width='405px'>");
                for (int i = 0; i < tb.Rows.Count; i++)
                {
                    st.Append("<tr><td align='left'><b>" + tb.Rows[i]["ten_nguoi_comment"].ToString().Trim() + "</b> (" + DateTime.Parse(tb.Rows[i]["ngay_comment"].ToString()).ToString("dd/MM/yyyy hh:mm:ss tt") + "):</td><td>&nbsp;</td></tr>");
                    st.Append("<tr><td align='left'><i>" + tb.Rows[i]["noi_dung"].ToString().Trim() + "</i></td><td>&nbsp;</td></tr>");
                    st.Append("<tr><td align='left'>&nbsp;</td><td>&nbsp;</td></tr>");
                    //st.Append("<div style='width: 405px;'><b>" + tb.Rows[i]["ten_nguoi_comment"].ToString().Trim() + "</b> (" + DateTime.Parse(tb.Rows[i]["ngay_comment"].ToString()).ToString("dd/MM/yyyy hh:mm:ss tt") + "):</div>");
                    //st.Append("<div style='width: 405px;'><i>" + tb.Rows[i]["noi_dung"].ToString().Trim() + "</i></div>");
                    //st.Append("<div>&nbsp;</div>");
                }
                st.Append("</table>");
               st.Append("</span>");
            }
            lbl_chitietcomment.Text = st.ToString();

        }

        protected void Button_reset_Click(object sender, EventArgs e)
        {
            this.Button_goi.Focus();
        }
    }
}